package com.jarvan.controller;

import com.alibaba.fastjson.JSON;
import com.jarvan.dto.TrainDto;
import com.jarvan.dto.TrainsDto;
import com.jarvan.enums.ResultEnum;
import com.jarvan.exception.TrainException;
import com.jarvan.form.TrainForm;
import com.jarvan.model.Trains;
import com.jarvan.service.TrainsService;
import com.jarvan.utils.PrefixUtil;
import com.jarvan.utils.ResultVoUtil;
import com.jarvan.vo.ResultVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Null;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Api(value = "火车api")
@Slf4j
@RestController
@RequestMapping("/train")
public class TrainController {

    @Autowired
    private TrainsService trainsService;

    @GetMapping("/findTrain")
    public ResultVo<List<TrainDto>> findBystation(@RequestParam("start") String start,
                                                @RequestParam("end") String end,
                                                  @RequestParam("date") String date){
        List<TrainDto> trains = trainsService.findByDepartureAndDistination(start, end, date);

        return ResultVoUtil.success(trains);
    }
}
